<template>
	<view class="termSelect">
		<picker mode="selector" :value="selectIndex" @change="change" :range="vm.choices" range-key="name">
			<view class="pickerInput">
				<text v-text="text"></text>
				<span class="icon_more"></span>
			</view>
		</picker>
	</view>
</template>

<script>
	
export default {
	name: 'term-select',
	props: {
		vm: {
			type: Object,
			required: true
		}
	},
	data() {
		let self = this;
		return {
			selectIndex: '',
		}
	},
	methods: {
		change(e) {
			this.vm.selectItem = this.vm.choices[e.detail.value];
			this.$emit('selectChange', this.vm.selectItem);
		},
	},
	computed: {
		text() {
			let text = this.vm.selectItem ? this.vm.selectItem.name : this.vm.placeHolder;
			return text;
		}
	},
	mounted() {
		
	},
	watch: {
		'vm.choices': {
			handler(choices) {
				let selectIndex = '';
				choices.map((item, index) => {
					if (item.isCurrentTerm) {
						selectIndex = index
					}
				})
				this.selectIndex = selectIndex;
				this.change({
					detail: {
						value: selectIndex
					}
				})
			},
		}
	}
}
</script>

<style lang="scss" scoped>
.termSelect {
	margin: 0 50upx;
	.icon_more{
		display: inline-block;
		vertical-align: middle;
		width: 0;
		height: 0;
		border: 10upx solid transparent;/*5px 足够了*/
		border-top-color:#000;/*top箭头向下 bottom箭头向上*/
		// margin-left: 10upx;
	}
	.pickerInput {
		height: 80upx;
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 0 10upx;
		text {
			font-size: 32upx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #666;
			line-height: 80upx;
		}
	}
	
	text {
		display: inline-flex;
		font-size: 28upx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #666;
		margin-right: 10upx;
	}
		
}
	
</style>
